package com.demo.service.impl;

import com.demo.dto.ClassesDTO;
import com.demo.dto.ClassesPageQueryDTO;
import com.demo.dto.StudentDTO;
import com.demo.dto.StudentPageQueryDTO;
import com.demo.mapper.ClassesMapper;
import com.demo.mapper.StudentMapper;
import com.demo.pojo.Classes;
import com.demo.pojo.Student;
import com.demo.result.PageResult;
import com.demo.service.StudentService;
import com.demo.vo.ClassesVO;
import com.demo.vo.StudentVO;
import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class StudentServiceImpl implements StudentService {
    @Autowired
    StudentMapper studentMapper;

    @Override
    public void save(StudentDTO studentDTO) {
        System.out.println(studentDTO);
        Student student=new Student();
        BeanUtils.copyProperties(studentDTO,student);
        studentMapper.addStudent(student);
    }

    @Override
    public void delete(String[] StuIDs) {
        for(String stuID:StuIDs){
            studentMapper.delete(stuID);
        }
    }

    @Override
    public void deleteById(String stuID) {
        studentMapper.delete(stuID);
    }

    @Override
    public void update(StudentDTO studentDTO) {
        studentMapper.update(studentDTO);
    }

    @Override
    public PageResult pageQuery(StudentPageQueryDTO studentPageQueryDTO) {
        System.out.println(studentPageQueryDTO);
        PageHelper.startPage(studentPageQueryDTO.getPage(), studentPageQueryDTO.getPageSize());
        Page<StudentVO> page = studentMapper.pageQuery(studentPageQueryDTO);
        long total = page.getTotal();
        List<StudentVO> records = page.getResult();
        return new PageResult(total, records);
    }
}
